#include <stdio.h>
#include <string.h>
#include "sub.h"

const char *prog;

static const struct subinfo sub_definitions[] = {
	{"optdebug", optdebug_main},
	{"ls",       ls_main},
	{"cut",      cut_main},
	{"shift",    shift_main},
#if 0
	{"dump",     dump_main,     "h"},
	{"pack",     pack_main,     "h"},
	{"make",     make_main,     "h"},
	{"split",    split_main},
	{"sort",     sort_main},
	{"cat",      cat_main},
	{"meta",     meta_main},
	{"test",     test_main,     "h"},
#endif
	{0,          default_main},
};

const struct subinfo *find_sub(const char *name)
{
	const struct subinfo *sub;
	for (sub = sub_definitions; sub->name; sub++)
		if (strcmp(name, sub->name) == 0) {
			prog = sub->name;
			return sub;
		}
	return sub;
}

int default_main(int argc, const char *const *argv)
{
	const struct subinfo *sub;
	(void)argc;
	printf("flvutils " VERSION "\n"
		"Usage: %s SUB { --help | [OPTION]... }\n"
		"\n"
		"SUB := {", argv[0]);
	for (sub = sub_definitions; sub->name; sub++)
		printf(" %s %s", sub->name, sub[1].name ? "|" : "}\n");
	return 0;
}
